package com.pai4j.pgc.dao;
import com.pai4j.pgc.entity.SubjectSubscribeEntity;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public interface ISubjectSubcribeDAO extends JpaSpecificationExecutor<SubjectSubscribeEntity>,
        JpaRepository<SubjectSubscribeEntity, Long> {
    
    
    /**
     * 查询某用户对某专题的关注关系
     *
     * @author: CYM-pai
     * @date: 2025/05/16 21:18
     **/
    SubjectSubscribeEntity findAllByUserIdAndSubjectId(String userId, Long subjectId);
    
    List<SubjectSubscribeEntity> findAllBySubjectIdAndType(Long subjectId, Integer type);

    /**
     * 统计某专题的订阅数量（关注该专题的用户数量）
     * 
     * @param subjectId 专题ID
     * @param status 订阅状态（有效订阅状态）
     * @return 订阅数量
     */
    @Query(value = "select count(s) from SubjectSubscribeEntity s where s.subjectId = ?1 and s.status = ?2")
    Long countBySubjectIdAndStatus(Long subjectId, Integer status);
}
